#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
using arr = vector<vector<bool>>;
const int N = 1e6 + 10, INF = 0x3f3f3f3f;

int n, m, k;
struct node
{
    vector<vector<bool>> mp;
    int cnt;
};

int d1[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
int d2[4][2] = { {2,0},{-2,0},{0,2},{0,-2} };

void solve()
{
    cin >> n >> m >> k;
    arr st(n, vector<bool>(m, 0));
    for (int i = 1;i <= k;i++) {
        int x, y;cin >> x >> y;
        x--, y--;
        st[x][y] = 1;
    }

    int ans = k;
    queue<node> q;
    q.push({ st, k });
    while (!q.empty()) {
        auto [a, cnt] = q.front();q.pop();
        ans = min(ans, cnt);
        if (ans == 0) break;
        for (int i = 0;i < n;i++)
            for (int j = 0;j < m;j++)
                for (int d = 0;d < 4;d++) {
                    int nx1 = i + d1[d][0], ny1 = j + d1[d][1];
                    int nx2 = i + d2[d][0], ny2 = j + d2[d][1];
                    if (nx2 >= 0 && nx2 < n && ny2 >= 0 && ny2 < m && a[i][j] == 1 && a[nx1][ny1] == 1 && a[nx2][ny2] == 0) {
                        arr t = a;
                        t[i][j] = 0;
                        t[nx1][ny1] = 0;
                        t[nx2][ny2] = 1;
                        q.push({ t,cnt - 1 });
                    }
                }
    }
    cout << ans << '\n';
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    cin >> T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}